package cn.bugstack.initializr.rigger.domain.service.module.impl;

import cn.bugstack.initializr.rigger.domain.model.ApplicationInfo;
import cn.bugstack.initializr.rigger.domain.model.EhCacheConfigInfo;
import cn.bugstack.initializr.rigger.domain.model.ProjectInfo;
import cn.bugstack.initializr.rigger.domain.service.module.BaseModule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.io.File;
@Service
public class GenerationEhCacheConfig extends BaseModule {
    private Logger logger = LoggerFactory.getLogger(GenerationEhCacheConfig.class);

    public void doGeneration(ProjectInfo projectInfo,String projectsRoot, String lastPackageName,String ehCacheClassName) throws Exception {

        EhCacheConfigInfo ehCacheConfigInfo = new EhCacheConfigInfo(projectInfo.getGroupId() + "." + lastPackageName,
                projectInfo.getName().toString());

        String packagePath = ehCacheConfigInfo.getPackageName().replace(".", "/") + "/config/";

        File file = new File(projectsRoot + projectInfo.getArtifactId() + "/src/main/java/" + packagePath,
                ehCacheClassName + ".java");

        // 写入文件
        super.writeFile(file, "EhCacheConfig.ftl", ehCacheConfigInfo);

        logger.info("创建缓存类 ehCacheConfigInfo.java {}", file.getPath());
    }
}
